home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
mc51bugs
/
q30453
< prev
next >
Wrap
Text File
|
1988-07-20
|
3KB
|
103 lines
Q30453 Incorrect Code Generation for Switch Statement
C Compiler
5.10
MS-DOS
Summary:
The compiler generates incorrect code for a switch statement under
specific circumstances.
The program has several case statements and the compiler detects
common code in two of the cases. It generates an unconditional jump to
a label that seems to be off by one instruction i.e., a certain path
is taken in cases where it should not be taken.
More Information:
The code generated for case 4: includes an unconditional jump to a
CALL to the function err_alarm(2). The compiler sees that the
CALL to err_alarm(2) is the same in case 2: and jumps to that
code. However, the condition of the loop is never evaluated.
Work around the problem by changing the if statement in case 4: as
follows:
case 4: /* Legal file name chars */
if (isgraph(char_in)
The following is a code example:
#include <ctype.h>
int context;
int strgin(inp_string,len,type)
char *inp_string; /* 1=string 2=hex 3=dec 4=file name */
int len, type; /* || 00=screen 10=window */
{
int char_in;
int i = 0;
int *prow, *pcol;
int row,col;
prow = &row;
pcol = &col;
i = strlen(inp_string);
do
{
if (!chin(&char_in))
continue;
if (i < len)
{
switch (type & 0x0f)
{
case 1: /* ASCII string */
if (0 == isprint(char_in))
continue;
break;
case 2: /* Hexidecimal only */
if (0 == isxdigit(char_in) && 0 == isspace(char_in))
{
err_alarm(2);
continue;
}
break;
case 3: /* Decimal only */
if (0 == isdigit(char_in))
{
err_alarm(3);
continue;
}
break;
case 4: /* Legal filename chars */
if (0 == isgraph(char_in))
{
err_alarm(2);
continue;
}
break;
default:
continue;
break;
}
if (type & 0x10)
wnwrtty((char)char_in, -1,-1);
else
scttywrt((char)char_in,-1);
inp_string[i++] = (char)char_in;
inp_string[i] = '\0';
}
else
{
err_alarm(2);
context = 44;
disp_help_line(94);
}
}
while (char_in != '\r');
}
Keywords: buglist5.10
Updated 88/07/21 03:19